#!/bin/sh
final="$@"

EXT=so
if [ $(uname) = "Darwin" ]; then
    EXT=dylib
fi

# add ros plugin if does not exist
if [ `expr "$final" : ".*libgazebo_ros_paths_plugin\.$EXT.*"` -eq 0 ]
then
    final="$final -g `catkin_find --first-only libgazebo_ros_paths_plugin.$EXT`"
fi

setup_path=$(pkg-config --variable=prefix gazebo)/share/gazebo/

# source setup.sh, but keep local modifications to GAZEBO_MASTER_URI
desired_master_uri="$GAZEBO_MASTER_URI"
. $setup_path/setup.sh
if [ "$desired_master_uri" = "" ]; then
	desired_master_uri="$GAZEBO_MASTER_URI"
fi

# Combine the commands
GAZEBO_MASTER_URI="$desired_master_uri" gzclient $final
